package np13.earth;

import java.util.LinkedList;
import java.util.List;

import np13.Slime;
import np13.ferry.Pier;
import np13.monads.HomeLandMonad;

/**
 * A homeland consists of: the information which slimes belong to this land, the
 * slimes which are already here and the pier connected to this land.
 */
public class HomeLand {

	/**
	 * A list of all slimes which belong to this land.
	 */
	private final List<Slime> slimesBornHere;

	/**
	 * The refugee-camp for evacuated slimes. Note that this is always a subset
	 * of slimesBornHere.
	 */
	private final List<Slime> refugeeCampForEvacuatedSlimes;

	/**
	 * The pier connected to this land.
	 */
	private final Pier pier;

	/**
	 * Initializes a homeland.
	 * 
	 * @param pier
	 *            The pier connected to this land.
	 * @param slimesBornHere
	 *            A list of all slimes which belong to this land.
	 */
	public HomeLand(Pier pier, List<Slime> slimesBornHere) {
		this.pier = pier;
		this.slimesBornHere = slimesBornHere;
		refugeeCampForEvacuatedSlimes = new LinkedList<Slime>();
	}

	/**
	 * 
	 * @return How many Slimes have made it home.
	 */
	public int campSize() {
		return refugeeCampForEvacuatedSlimes.size();
	}

	/**
	 * Permanently places a slime on this land.
	 * 
	 * @param slime
	 *            The slime to be placed.
	 */
	public void dumpSlime(Slime slime) {
		if (!smellsGood(slime))
			throw new IllegalArgumentException();
		refugeeCampForEvacuatedSlimes.add(slime);
	}

	/**
	 * @return The pier connected to this land.
	 */
	public Pier getPier() {
		return pier;
	}

	/**
	 * Checks if a slime belongs to this land. May only be called by
	 * {@link HomeLandMonad} for a Slime being on this land.
	 * 
	 * @param slime
	 *            The slime to be checked.
	 * @return True if the slime belongs to this land, false otherwise.
	 */
	public boolean smellsGood(Slime slime) {
		return slimesBornHere.contains(slime);
	}
}
